//
//  DmDocMgr.h
//  FoxitApp
//
//  Created by sijia_liu on 15/4/27.
//
//

#import <Foundation/Foundation.h>
#import "IUndoRedo.h"
#import "OFDViewControl.h"
#import "FSPDFObjC.h"
#import "IDvDocViewer.h"

typedef enum
{
    MemoryMode_Low = 0,
    MemoryMode_Middle,
    MemoryMode_High,
    
} MemoryMode;

#define FPDF_INIT_MEMORY_SIZE (10 * 1024 * 1024)
#define FPDF_MAX_MEMORY_SIZE ((([RDKUtility getMemoryMode]==MemoryMode_Low)?40:(([RDKUtility getMemoryMode]==MemoryMode_Middle)?120:200)) * 1024 * 1024)
#define HALFTONE_LIMIT 2048 * 2048


#pragma mark -
#pragma mark Internal Init

#define LICENSE_KEY @"CNMOa7tZNVXQOXqnVmV/yTwnlEVejuvXhd/hUIJGX2Wd/7ga7KwRDg=="
#define UNLOCK_CODE @"Pe6s4v+H9JZasMGjFq6JqogAYsq+DdwYuTRNo5p32EL460pVdpXz5dB4tLmXzm2bV/oy9VJGVfcXBc2M+Ofms34waO8RMRB8540qbA1sIXSIkMgC8ju6eio2uXJVzQc0GiSrLTodwSY07M/3DaB0ymHCZ3N6HZXHWk7MFiNwdvUCQxkGqUqPMB27dKyi5yvS9lx84EramywIB8YZCnKjFF3HjJMCF+k6oLwDyf9MWnobL+rKh9pTKfeTOZJfJJbpncGdrRZNbw8yiYWdis0EzbSWzKUwGBWDXXSSvBrjMGdWEZtYiFqCTly6JyOW8HIKfoieiJ5bivzqyqUn2CnhkXRBY0NAZyg7hr8aIrou1QH0nz0i3RvuUCtGak/kLJ8efQ5/OmGuWxJfhzm5rfGhYEbGl3ae4JySJ6xPmfDhHpNVb9RbqVoLjiQZ4MED9keH50ZeuPd0Pxx/4NxGy1KTqEx5VQgUF6s8Fv/tYqIaRW1Tv19A76nmWyUlaRhpz7HrSuItTk+s/t86AsiwACqZ+Dqyv0C2seiyYQCZkS1SN0jLnNWma8voOZ663hzoc+IAhNjcETLoOWZ1AYggwpOaNFLCxpmgnYZSTQP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fGHx+jiCTr97b+CXgcJO4XsLv6Ba6eWLjq6JwsWV/eiT+5et8SYhuue1/0ir2nK9TxCW5icU9"


#define FSCRT_RMS_CANCEL	-24

//@class DmAnnot;
@class DmDocument;
@class DmFileDescriptor;
@class IUndoRedo;
@class RDKTaskServer;
@class FSPauseCallback;

//@class IDmUndoItem;
//@class IUndoEventListener;

//@class DmPage;

//@protocol IAnnotEventListener <NSObject>
//
//@required
//- (void)onAnnotAdded:(DmPage*)page annot:(id<IAnnot>)annot;
//- (void)onAnnotDeleted:(DmPage*)page annot:(id<IAnnot>)annot;
//- (void)onAnnotModified:(DmPage*)page annot:(id<IAnnot>)annot;
//- (void)onCurrentAnnotChanged:(id<IAnnot>)lastAnnot currentAnnot:(id<IAnnot>)currentAnnot;
//
//@end

//@protocol IUndoEventListener <NSObject>
//
//- (void)itemWillAdd:(DmDocument*)document item:(id<IDmUndoItem>)item;
//- (void)itemAdded:(DmDocument*)document item:(id<IDmUndoItem>)item;
//- (void)willUndo:(DmDocument*)document item:(id<IDmUndoItem>)item;
//- (void)undoFinished:(DmDocument*)document item:(id<IDmUndoItem>)item;
//- (void)willRedo:(DmDocument*)document item:(id<IDmUndoItem>)item;
//- (void)redoFinished:(DmDocument*)document item:(id<IDmUndoItem>)item;
//- (void)willClearUndo:(DmDocument*)document;
//- (void)clearUndoFinished:(DmDocument*)document;
//
//@end

@protocol IDmDocEventListener <NSObject>

@required
- (void)onDocumentWillOpen:(DmFileDescriptor*)descriptor;
- (void)onDocumentOpened:(DmDocument*)document error:(int)error;
- (void)onDocumentWillClose:(DmDocument*)document;
- (void)onDocumentClosed:(DmDocument*)document error:(int)error;
- (void)onDocumentWillSave:(DmDocument*)document;
- (void)onDocumentOpenFailed:(DmFileDescriptor*)fileDescriptor error:(int)error;

@end

@protocol IDocReloadEventListener <NSObject>

@required
- (void)onDocumentWillReload:(DmDocument*)document; //说明内容有变化 清除缓存 重新拿页面信息
- (void)onDocumentReloaded:(DmDocument*)document;

@end

@protocol IDmPageEventListener <NSObject>

@required
- (void)onPageDeleted:(NSArray*)indexArray;

@end

@protocol IGSDKEventListener <NSObject>

- (int)onEvent:(void const*) clientData senderObject:(void const*)senderObject senderObjectType:(unsigned long)senderObjectType eventType:(unsigned long)eventType eventData:(void const*)eventData;

@end


typedef void (^OpenDocResult)(DmDocument* doc, int err);

@interface DmPause : FSPauseCallback
-(BOOL)needPauseNow;
@end


@interface DmDocMgr : NSObject
{
    DmPause* _pauseHandler;
}
@property (nonatomic, retain) DmDocument *currentDoc;
@property (nonatomic, retain) NSMutableArray *docs;
@property (nonatomic, retain) RDKTaskServer *taskServer;

-(DmPause*)getPauseHandler;
-(void)setup;

- (BOOL)openDocument:(DmFileDescriptor*)descriptor completion:(void(^)(enum FS_ERRORCODE error))completion;
- (BOOL)closeDocument:(BOOL)save CleanUp:(void (^)())cleanup;
- (void)onDocumentWillSave:(DmDocument*)document;
- (void)onDocumentSaved:(DmDocument*)document error:(int)error;
- (void)onDocumentReloaded:(DmDocument*)document;

- (void)registerVCDocEventListener:(id<IDocEventListener>)listener;
- (void)unregisterVCDocEventListener:(id<IDocEventListener>)listener;

- (void)registerDocEventListener:(id<IDmDocEventListener>)listener;
- (void)unregisterDocEventListener:(id<IDmDocEventListener>)listener;

//- (void)registerAnnotEventListener:(id<IAnnotEventListener>)listener;
//- (void)unregisterAnnotEventListener:(id<IAnnotEventListener>)listener;

- (void)registerDocReloadEventListener:(id<IDocReloadEventListener>)listener;
- (void)unRegisterDocReloadEventListener:(id<IDocReloadEventListener>)listener;

- (void)registerGSDKEventListener:(id<IGSDKEventListener>)listener;
- (void)unregisterGSDKEventListener:(id<IGSDKEventListener>)listener;
//- (NSArray*)getGSDKEventListeners;

- (void)registerUndoEventListener:(id<IUndoEventListener>)listener;
- (void)unregisterUndoEventListener:(id<IUndoEventListener>)listener;

- (void)onPagesDeleted:(NSArray*)indexArray;
- (void)registerPagesEventListener:(id<IDmPageEventListener>)listener;
- (void)unregisterPagesEventListener:(id<IDmPageEventListener>)listener;

- (void)undoItemWillAdd:(DmDocument*)document item:(id<IDmUndoItem>)item;
- (void)undoItemAdded:(DmDocument*)document item:(id<IDmUndoItem>)item;
- (void)willUndo:(DmDocument*)document item:(id<IDmUndoItem>)item;
- (void)undoFinished:(DmDocument*)document item:(id<IDmUndoItem>)item;
- (void)willRedo:(DmDocument*)document item:(id<IDmUndoItem>)item;
- (void)redoFinished:(DmDocument*)document item:(id<IDmUndoItem>)item;
- (void)willClearUndo:(DmDocument*)document;
- (void)clearUndoFinished:(DmDocument*)document;

//- (void)annotAdded:(DmPage*)page annot:(id<IAnnot>)annot;
//- (void)annotModify:(DmPage*)page annot:(id<IAnnot>)annot;
//- (void)annotDeleted:(DmPage*)page annot:(id<IAnnot>)annot;

- (BOOL)openDocument:(DmFileDescriptor*)descriptor result:(OpenDocResult)result;
- (BOOL)closeDocument:(DmDocument*)doc save:(BOOL)save CleanUp:(void (^)())cleanup;

@end
